//
//  BackViewController.m
//  ThePrivateKitchen
//
//  Created by lirui on 16/2/25.
//  Copyright © 2016年 www.lanou3g.com蓝鸥科技. All rights reserved.
//

#import "BackViewController.h"

#import <MessageUI/MessageUI.h>
#import "MyPCH.pch"
#import "Frame.h"

@interface BackViewController ()<MFMailComposeViewControllerDelegate>
@property (nonatomic, retain) UILabel *textLabel;
@end

@implementation BackViewController

- (void)dealloc
{
    [_textLabel release];
    [super dealloc];
}
#pragma mark -视图将要出现
-(void)viewWillAppear:(BOOL)animated
{
    self.tabBarController.tabBar.hidden = YES;
}
#pragma mark -视图将要消失
-(void)viewWillDisappear:(BOOL)animated
{
    self.tabBarController.tabBar.hidden = NO;

}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor  =[ UIColor whiteColor];
        self.navigationItem.title = @"用户反馈";
       //重写左按钮
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[[UIImage imageNamed:@"left@3x"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:self action:@selector(leftAction:)];
    UIImageView *buttom =[[ UIImageView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    buttom.image =[ UIImage imageNamed:@"背景4.jpeg"];
    [self.view addSubview:buttom];
    [buttom release];
    
    self.textLabel = [[ UILabel alloc] initWithFrame:CGRectMake(0, 100 * WIDTH, WIDTH * 375, HEIGHT * 100)];
    self.textLabel.backgroundColor = [ UIColor clearColor];
    self.textLabel.text = @"欢迎您反馈使用产品的感受和建议";
    [self.view addSubview:self.textLabel];
    self.textLabel.textAlignment = NSTextAlignmentCenter;
    [_textLabel release];
    UIButton *ok =[ UIButton buttonWithType:UIButtonTypeSystem];
    ok.frame = CGRectMake(200 *WIDTH, 200 *HEIGHT, 50 *WIDTH, 50 *HEIGHT);
    [ok setTitle:@"确定" forState:UIControlStateNormal];
    [ok addTarget:self action:@selector(okAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:ok];
    
    UIButton *diss =[ UIButton buttonWithType:UIButtonTypeSystem];
    diss.frame = CGRectMake(80 *WIDTH, 200 *HEIGHT, 50 *WIDTH, 50 *HEIGHT);
    [diss setTitle:@"取消" forState:UIControlStateNormal];
    [diss addTarget:self action:@selector(dissAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:diss];
    
    
    
}
-(void)leftAction:(UINavigationItem *)le
{
    [self.navigationController popViewControllerAnimated:YES];
}
-(void)okAction
{
    if ([MFMailComposeViewController canSendMail]) { // 用户已设置邮件账户
        [self sendEmailAction]; // 调用发送邮件的代码
    }
}

-(void)dissAction
{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)sendEmailAction
{
    // 邮件服务器
    MFMailComposeViewController *mailCompose = [[MFMailComposeViewController alloc] init];
    // 设置邮件代理
    [mailCompose setMailComposeDelegate:self];
    // 设置邮件主题
    [mailCompose setSubject:@"我是邮件主题"];
    // 设置收件人
    [mailCompose setToRecipients:@[@"1369324218@qq.com"]];
    // 设置抄送人
    [mailCompose setCcRecipients:@[@"1369324218@qq.com"]];
    // 设置密抄送
    [mailCompose setBccRecipients:@[@"shana_happy@126.com"]];
    /**
     *  设置邮件的正文内容
     */
    NSString *emailContent = @"我是邮件内容";
    // 是否为HTML格式
    [mailCompose setMessageBody:emailContent isHTML:NO];
    // 如使用HTML格式，则为以下代码
    //	[mailCompose setMessageBody:@"<html><body><p>Hello</p><p>World！</p></body></html>" isHTML:YES];
    /**
     *  添加附件
     */
    UIImage *image = [UIImage imageNamed:@"image"];
    NSData *imageData = UIImagePNGRepresentation(image);
    [mailCompose addAttachmentData:imageData mimeType:@"" fileName:@"custom.png"];
    NSString *file = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"pdf"];
    NSData *pdf = [NSData dataWithContentsOfFile:file];
    [mailCompose addAttachmentData:pdf mimeType:@"" fileName:@"7天精通IOS233333"];
    // 弹出邮件发送视图
    [self presentViewController:mailCompose animated:YES completion:nil];
}
//MFMailComposeViewControllerDelegate的代理方法：

- (void)mailComposeController:(MFMailComposeViewController *)controller
          didFinishWithResult:(MFMailComposeResult)result
                        error:(NSError *)error
{
    switch (result)
    {
        case MFMailComposeResultCancelled: // 用户取消编辑
            NSLog(@"Mail send canceled...");
            break;
        case MFMailComposeResultSaved: // 用户保存邮件
            NSLog(@"Mail saved...");
            break;
        case MFMailComposeResultSent: // 用户点击发送
            NSLog(@"Mail sent...");
            break;
        case MFMailComposeResultFailed: // 用户尝试保存或发送邮件失败
            NSLog(@"Mail send errored: %@...", [error localizedDescription]);
            break;
    }
    // 关闭邮件发送视图
    [self dismissViewControllerAnimated:YES completion:nil];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
